
#include "stdio.h"
#include "cJSONX.h"

int main()
{
	cJSON *root = NULL;
	cJSON *obj = NULL;
	cJSON *sub = NULL;
	int i, max, num = 0;
	char str[64] = { 0 };

	root = CJX_NEW_OBJ();
	CJX_SET_NUM(root, "num1", 1);
	CJX_SET_NUM(root, "num2", 2);
	CJX_SET_STR(root, "str1", "kanghua");

	CJX_SET_ARRAY_NUM(root, "array1", 3);
	CJX_SET_ARRAY_NUM(root, "array1", 4);

	CJX_SET_ARRAY_STR(root, "array2", "aa");
	CJX_SET_ARRAY_STR(root, "array2", "bb");

	sub = CJX_NEW_OBJ();
	CJX_SET_STR(sub, "sub1", "kanghua_sub1");
	CJX_SET_STR(sub, "sub2", "kanghua_sub2");
	CJX_SET_OBJ(root, "sub", sub);

	CJX_GET_NUM(root, "num1", num);
	printf("\r\n num: %d", num);

	CJX_GET_NUM(root, "num2", num);
	printf("\r\n num: %d", num);

	CJX_GET_STR(root, "str1", str);
	printf("\r\n str: %s", str);

	CJX_GET_ARRAY_FOR(root, "array1", obj)
	{
		printf("\r\n array1 num: %d", CJX_OBJ2INT(obj));
	}

	CJX_GET_ARRAY_SIZE(root, "array2", max);
	for(i = 0; i < max; i++)
	{
		CJX_GET_ARRAY_STR_IDX(root, "array2", i, str);
		printf("\r\n array2 str: %s", str);
	}

	printf("\n %s.", cJSON_Print(root));
	CJX_END_OBJ(root);
	return 0;
}
